// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
var Vue = require('vue')
var Axios = require( 'axios')
var  MintUi =  require('mint-ui')
var  Moment = require('moment')
import './config/rem'
import './config/interaction'
import store from './store'
import App from './App'
import router from './router'
 
Moment.locale('zh-cn');
Vue.prototype.$Axios = Axios;
Vue.use(MintUi);

Axios.defaults.withCredentials = true
// 配置公共loading
Axios.interceptors.request.use(function (config) {
    MintUi.Indicator.open({
      text: '加载中...',
      spinnerType: 'fading-circle'
    });
    return config;
  });
Axios.interceptors.response.use(function (response) {
  MintUi.Indicator.close();
  return response;
},function(err){
  MintUi.Indicator.close();
  if (err && err.response) {
    switch (err.response.status) {
      case 400:
        MintUi.Toast({
          message: '请求错误',
          position: 'middle',
          duration: 1000
        });
        break
      case 401:
        MintUi.Toast({
          message: '未授权，请登录',
          position: 'middle',
          duration: 1000
        });
        break
      case 403:
        MintUi.Toast({
          message: '拒绝访问',
          position: 'middle',
          duration: 1000
        });
        break
      case 404:
        MintUi.Toast({
          message: `请求地址出错: ${err.response.config.url}`,
          position: 'middle',
          duration: 1000
        });
        break
      case 408:
        MintUi.Toast({
          message: `请求超时`,
          position: 'middle',
          duration: 1000
        });
        break
      case 500:
        MintUi.Toast({
          message: `服务器内部错误`,
          position: 'middle',
          duration: 1000
        });
        break
      case 501:
        MintUi.Toast({
          message: `服务未实现`,
          position: 'middle',
          duration: 1000
        });
        break
      case 502:
        MintUi.Toast({
          message: `网关错误`,
          position: 'middle',
          duration: 1000
        });
        break
      case 503:
        MintUi.Toast({
          message: `服务不可用`,
          position: 'middle',
          duration: 1000
        });
        break
      case 504:
        MintUi.Toast({
          message: `网关超时`,
          position: 'middle',
          duration: 1000
        });
        break
      case 505:
        MintUi.Toast({
          message: `HTTP版本不受支持`,
          position: 'middle',
          duration: 1000
        });
        break
      default:
    }
  }
  return Promise.reject(err)
});

// 引入组件文件
import '@/assets/css/mint-ui.css'
// 引入公共css文件
import '@/assets/css/common.css'
import '@/assets/font/iconfont.css'

// 引入自己的公共组建
import MyUl from '@/components/common/myUl'
import MyLi from '@/components/common/myLi'
import NavBar from '@/components/common/navBar'

Vue.component(MyUl.name,MyUl);
Vue.component(MyLi.name,MyLi);
Vue.component(NavBar.name,NavBar)
// 设置过滤器
  // 字符串切割
Vue.filter('cutStr',(value,length)=>{
  if(!value) return '';
  if(value.length!=0){
    return value.substring(0,length) + '...'
  }
})
  //格式化时间
Vue.filter('formatDate',(value,str)=>{
  if(!value) return '';
  if(value!=''){
    return Moment(value).format(str)
  }
})

Vue.filter('convertDate',(value,str)=>{
  if(!value) return '';
  if(value!=''){
    return Moment(value).startOf('second').fromNow();
  }
})


Vue.config.productionTip = false


/* eslint-disable no-new */
new Vue({
  el: '#app',
  store,
  router,
  components: { App },
  template: '<App/>'
})
